/**
 * @author 董一华
 * @since 1.00
 * @version 1.00
 * 
 * 导出EXCEL按钮控件
 * 参数说明：
 * 1. table可以不写，缺省值为mytable
 * 2. onclick可以不写，缺省值为excelExport()
 * table与onclick不能同时使用
 * 3. value可以不写，为按钮显示名称，默认值为“导出EXCEL”
 * 4. noprint:不显示打印按钮，默认为显示打印按钮
 * 
 * 使用说明：
 * jsp中使用范例(只有三种用法)：
 * 1.<htdz-tag:ButtonExcelTag/>:用excelExport()(表名为mytable)导出EXCEL
 * 2.<htdz-tag:ButtonExcelTag table="tablename"/>:用excelExportByTableName(tablename)导出EXCEL
 * 3.<htdz-tag:ButtonExcelTag onclick="test(xxx)"/>:用test(xxx)导出EXCEL
 * 
 * 修订列表： v1.00 2009-11-12 
 * 			修订人：董一华 
 * 			修订内容：初始版本
 * 
 */

package com.zjht.gmcc.bean.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import com.zjht.gmcc.bean.util.MyFormat;

public class ButtonExcelTag extends TagSupport {
	private static final long serialVersionUID = 7343418033252888637L;
	private String table;
	private String onclick;
	private String value;
	private boolean noprint;

	public ButtonExcelTag() {
	}

	@SuppressWarnings("static-access")
	public int doStartTag() throws JspException {
		String table = this.table;
		String onclick = this.onclick;
		String value = this.value;
		boolean noprint = this.noprint;

		if (table != null && table.length() > 0) {
			onclick = "excelExportByTableName('" + table + "')";
		} else if (!MyFormat.isStrNull(onclick)) {

		} else {
			onclick = "excelExport()";
		}
		if (value == null || value.length() == 0) {
			value = "导出EXCEL";
		}
		StringBuilder html = new StringBuilder();

		try {
			html.append("<input type=\"button\" onclick=\"");
			html.append(onclick);
			html.append("\" ");
			html.append(MyFormat.getButtonClass(value));
			html.append(" />");
			if (!noprint) {
				html.append(" <input type=\"button\" onclick=\"javascript:");
				if (table != null && table.length() > 0) {
					html.append("printMeByTableName('" + table + "')");
				} else {
					html.append("printMe()");
				}
				html.append("\" ");
				html.append(MyFormat.getButtonClass("打 印"));
				html.append(" />");
			}
			pageContext.getOut().print(html.toString());
		} catch (Exception e) {
			throw new JspException(e.getMessage());
		}
		html = null;
		return this.SKIP_BODY;
	}

	public void setTable(String table) {
		this.table = table;
	}

	public void setOnclick(String onclick) {
		this.onclick = onclick;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public void setNoprint(String noprint) {
		this.noprint = "true".equals(noprint);
	}

	public void setNoprint(boolean noprint) {
		this.noprint = noprint;
	}
}
